import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { UserInfo } from '@/api/account/index'

export const useUserStore = defineStore(
  'his-user',
  () => {
    const hospitalName = ref('')
    const token = ref('')
    const userInfo = ref<UserInfo>({
      id: '',
      username: '',
      email: '',
      phone: '',
      avatar: '',
      name: '',
      title: '',
      job: '',
      sex: '',
      branchCode: '',
      deptCCode: '',
      deptName: '',
      branchName: '',
    })

    function setToken(data: string) {
      token.value = data
    }

    // Set setUserInfo
    function setUserInfo(data: UserInfo) {
      userInfo.value = data
    }

    return { token, userInfo, hospitalName, setToken, setUserInfo }
  },
  {
    persist: {
      storage: sessionStorage,
    },
  }
)
